# -*- coding: utf-8 -*-
class SaleReturned < ActiveRecord::Base
  has_many :sale_returned_details ,:dependent => :destroy  #级联删除子表

  belongs_to :customer
  belongs_to :employee      #制单人员
  belongs_to :department
  belongs_to :company
  belongs_to :warehouse
  
  belongs_to :sale_order

  belongs_to :associate_auditor, :class_name => 'Employee', :foreign_key => 'associate_auditor_id'
  belongs_to :warehouse_employee, :class_name => 'Employee', :foreign_key => 'warehouse_employee_id'


  scope :findAllReturnedSales, ->(conditionsStr,conditionsHash,paramsHash) { includes( [:employee,:department,:customer,:associate_auditor,:warehouse,:warehouse_employee,:sale_order,:sale_returned_details]).where([conditionsStr,conditionsHash]).offset(paramsHash[:offset]).limit(paramsHash[:limit]).order('sale_returneds.updated_at DESC')}

  scope :countAllReturnedSales, ->(conditionsStr,conditionsHash) { includes( [:sale_returned_details]).where([conditionsStr,conditionsHash]).count()}

end
